package com.gegao.somethinginteresting.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.gegao.somethinginteresting.R;
import com.gegao.somethinginteresting.adapter.viewpagerAdapter.FlushAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import io.realm.Realm;

public class LaucherActivity extends AppCompatActivity {

    @Bind(R.id.vp_flush)
    ViewPager vpFlush;
    @Bind(R.id.rb_point_1)
    RadioButton rbPoint1;
    @Bind(R.id.rb_point_2)
    RadioButton rbPoint2;
    @Bind(R.id.rb_point_3)
    RadioButton rbPoint3;
    @Bind(R.id.rb_point_4)
    RadioButton rbPoint4;
    @Bind(R.id.rb_point_5)
    RadioButton rbPoint5;
    @Bind(R.id.rg_flush_point)
    RadioGroup rgFlushPoint;
    @Bind(R.id.bt_enter)
    Button btEnter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_laucher);
        ButterKnife.bind(this);

        //Create a RealmConfiguration which is to locate Realm file in package's "files" directory.
//        Realm myRealm = Realm.getInstance(this);
        initWidght();

    }

    private void initWidght() {
        List<Integer> imageResourceIdList = new ArrayList<>();
        imageResourceIdList.add(R.mipmap.image_flush_1);
        imageResourceIdList.add(R.mipmap.image_flush_2);
        imageResourceIdList.add(R.mipmap.image_flush_3);
        imageResourceIdList.add(R.mipmap.image_flush_4);
        imageResourceIdList.add(R.mipmap.image_flush_5);

        final List<Integer> radioButtonIdList = new ArrayList<>();
        radioButtonIdList.add(R.id.rb_point_1);
        radioButtonIdList.add(R.id.rb_point_2);
        radioButtonIdList.add(R.id.rb_point_3);
        radioButtonIdList.add(R.id.rb_point_4);
        radioButtonIdList.add(R.id.rb_point_5);

        rgFlushPoint.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

            }
        });

        vpFlush.setAdapter(new FlushAdapter(this, imageResourceIdList));
        vpFlush.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 4) {
                    btEnter.setVisibility(View.VISIBLE);
                } else {
                    btEnter.setVisibility(View.GONE);
                }
                rgFlushPoint.check(radioButtonIdList.get(position));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        btEnter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LaucherActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
            }
        }
        );
    }
}
